﻿using Microsoft.IdentityModel.Tokens;

namespace GatewaySwagger.Jwt;

public static class JwtTokenHelper
{
    /// <summary>
    ///  Create  a TokenValidationParameters instance
    /// </summary>
    /// <param name="tokenConfig"></param>
    /// <returns></returns>
    public static TokenValidationParameters GenarateTokenValidationParameters(JwtConfig tokenConfig) =>
        new ()
        {
            ValidateIssuer = tokenConfig.ValidateIssuer,
            ValidIssuer = tokenConfig.ValidIssuer,
            ValidateAudience = tokenConfig.ValidateAudience,
            ValidAudience = tokenConfig.ValidAudience,
            ValidateIssuerSigningKey = tokenConfig.ValidateIssuerSigningKey,
            IssuerSigningKey = new SymmetricSecurityKey(tokenConfig.Encoding.GetBytes(tokenConfig.SymmetricSecurityKey)),
            ValidateLifetime = tokenConfig.ValidateLifetime,
            RequireExpirationTime = tokenConfig.RequireExpirationTime,
            ClockSkew = TimeSpan.FromSeconds(tokenConfig.ClockSkew),
        };
}
